package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.ht.medicaltreatment.bean.OrderAllBean
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class OrderStockViewModel : BaseViewModel() {

    fun requestAllData(onResult:(MutableList<OrderAllBean>)->Unit){
        viewModelScope.launch {
            val bean = mApi.requestAllData()
            when(bean){
                is ApiResult.Success -> onResult(bean.data.data!!)
                is ApiResult.Error -> ToastUtils.showShort(bean.errorMessage)
            }
        }
    }

    fun requestOverData(onResult:(MutableList<OrderAllBean>)->Unit){
        viewModelScope.launch {
            val bean = mApi.requestOverData()
            when(bean){
                is ApiResult.Success -> onResult(bean.data.data!!)
                is ApiResult.Error -> ToastUtils.showShort(bean.errorMessage)
            }
        }
    }

    fun requestNotData(onResult:(MutableList<OrderAllBean>)->Unit){
        viewModelScope.launch {
            val bean = mApi.requestNotData()
            when(bean){
                is ApiResult.Success -> onResult(bean.data.data!!)
                is ApiResult.Error -> ToastUtils.showShort(bean.errorMessage)
            }
        }
    }
}
